<?PHP

/**
 *	Process takes care of any forms that are
 *	sent over Mullet.
 */

if (isset($_POST['process']))
{
	/**
	 *	SUBSCRIBE
	 *
	 *		- If a user is trying to subscribe
	 *		a character to an event, we make a
	 *		new instance of Subscriber and pass 
	 *		the form data to the function.
	 *
	 *		- Found on: event.php, events.php
	 */

	if ($_POST['process'] == 'subscribe')
	{
		$subscriber = new subscriber($mul_db, $smf_db);
		$result = $subscriber->setSubscriber($_POST);
	}





	/**
	 *	ADMIN
	 *
	 *		- Forms that belong to an officer are
	 *		handled here.
	 *
	 */
	elseif ($_POST['process'] == 'admin')
	{
		/**
		 *		Part I
		 *
		 *		- This form is from the event page where
		 *		we need to mark people for attendence
		 *		or remove them completely from the event.
		 *
		 *		- This is the only way we can actually
		 *		remove characters from the event, otherise
		 *		the user has to mark their character
		 *		"unavailable."
		 *
		 *		- Officers use checkboxes to select which
		 *		characters they're updating, so we need to 
		 *		loop through each one and take an action.
		 *
	 	 */

		$users = array();

		foreach($_POST['attendees'] as $attendee)
		{
			// New instance of subscriber.
			unset($subscriber);
			$subscriber = new subscriber($mul_db, $smf_db, $attendee);


			// Store the subscription IDs for later.
			if (!array_key_exists($subscriber->uid, $users))
				$users[$subscriber->uid][] = $subscriber->sid;


			// What are we doing with them?
			switch ($_POST['action'])
			{
				case 'attend': $subscriber->setAttending($_POST['event_id']); break;
				case 'remove': $subscriber->removeFromEvent(); break;
			}
		}

		unset($attendee);





		/**
		 *		Part II
		 *
		 *		- After we're done setting attendence, we
		 *		need to make sure that a user doesn't have two or more
		 *		characters attending the event. That just makes
		 *		for confusion all around.
		 *
	 	 */

		if ($_POST['action'] == 'attend')
			$subscriber->unattendSurplusCharacters($users, $_POST['event_id']);
	}
}

?>